<template>
  <div class="table">
    <el-table
      v-loading="loading"
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
      :header-cell-style="headerCellStyle"
      algin="center"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column
        v-for="item in tableHead"
        :label="item.label"
        :prop="item.prop"
        :key="item.label"
        :show-overflow-tooltip="tooltip"
      >
        <template slot-scope="scope">
          {{ scope.row.date }}
          <div class="button-row" v-if="item.type == 'button'">
            <el-button
              type="success"
              v-if="item.button && item.button.update"
              size="mini"
              @click="$emit('updateNotice', scope.row, 1)"
              >修改</el-button
            >
            <el-button
              type="danger"
              v-if="item.button && item.button.delete"
              size="mini"
              @click="$emit('deleteNotice', scope.row)"
              >删除</el-button
            >
          </div>
          <div class="img-row" v-else-if="item.type == 'img'">
            <el-image
              v-if="item.imgclick"
              style="width: 50px; height: 50px"
              :src="
                item.formatter
                  ? item.formatter(scope.row, scope.row[item.prop]).url
                  : [scope.row[item.prop]]
              "
              :preview-src-list="
                item.formatter
                  ? item.formatter(scope.row[item.prop]).images
                  : [scope.row[item.prop]]
              "
            >
              {{ scope.row[item.prop] }}
            </el-image>
            <el-avatar
              shape="square"
              :size="50"
              :src="
                item.formatter
                  ? item.formatter(scope.row, scope.row[item.prop])
                  : scope.row[item.prop]
              "
            >
            </el-avatar>
          </div>
          <el-switch
            v-else-if="item.type == 'switch'"
            @change="$emit('stateChange', scope.row[item.prop])"
            v-model="scope.row.state"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="1"
            inactive-value="0"
          >
          </el-switch>
          <div class="text" v-else>
            <span
              v-if="item.type == 'isclick'"
              @click="$emit('textView', scope.row)"
              style="cursor: pointer; color: blue; text-decoration: underline"
            >
              {{ scope.row[item.prop] }}
            </span>
            <span
              v-else
              style="color: blue; text-decoration: underline; cursor: pointer"
            >
              {{ !scope.row[item.prop] ? "---" : scope.row[item.prop] }}
            </span>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  props: {
    loading: {
      type: Boolean,
      default: true,
    },
    tableData: {
      type: Array,
      default: () => [],
    },
    tableHead: {
      type: Array,
      default: () => [],
    },
    headerCellStyle: {
      type: Object,
      default: () => {
        return {
          background: "#f4f4f4",
          fontSize: "18px",
        };
      },
    },
    tooltip: {
      type: Boolean,
      default: true,
    },
  },
  mounted() {},
  methods: {
    handleSelectionChange(val) {
      this.$emit('multipleSelection',val)
      console.log(val);
    },
  },
};
</script>

<style lang="sass" scoped>

</style>>
</style>